#pragma once
#include "stdafx.h"

class QueryResult;


class TextQuery
{
public:
	using line_no = std::vector<std::string>::size_type;
	TextQuery();
	TextQuery(ifstream &infile);
	~TextQuery();

	QueryResult query(const string &) const;

private:
	shared_ptr<vector<string>> lpLinesVec;
	map<string, shared_ptr<set<line_no>>> wordRowsMap;

public:
	void loadFile(ifstream &infile);
};


class QueryResult
{
	friend ostream& print(ostream&, const QueryResult&);
	friend std::ostream& operator<<(std::ostream&, const QueryResult&);
public:
	QueryResult();
	QueryResult(string s, shared_ptr<set<TextQuery::line_no>> set, shared_ptr<vector<string>> lines)
		:sought(s), lpWordRowsSet(set), lpLinesVec(lines) {}
	~QueryResult();
	set<TextQuery::line_no>::iterator begin() {
		return lpWordRowsSet->begin();
	}
	set<TextQuery::line_no>::iterator end() {
		return lpWordRowsSet->end();
	}

	const shared_ptr<vector<string>> get_file() const { return lpLinesVec; }
private:
	string sought;
	shared_ptr<set<TextQuery::line_no>> lpWordRowsSet;
	shared_ptr<vector<string>> lpLinesVec;

};